
#include "udp_var.h"
#include "udpcksum.h"

#include <netinet/ip.h>
#include <netinet/ip6.h>

void udp_write(char * buf, int userlen) {

    struct udpiphdr * ui;
    struct ip * ip;

    ip = (struct ip *)buf;
    ui = (struct udpiphdr * )buf;

    bzero(&ui, sizeof(ui));



    ui->ui_len = htons((uint16_t)(sizeof(struct udphdr) + userlen));
    userlen   += sizeof(struct udpiphdr);

    ui->ui_pr = IPPROTO_UDP;
    ui->ui_src.s_addr = ((struct sockaddr_in * )local)->sin_addr.s_addr;
    ui->ui_dst.s_addr = ((struct sockaddr_in * )dest)->sin_addr.s_addr;

    ui->ui_sport = ((struct sockaddr_in * )local)->sin_port;
    ui->ui_dport = ((struct sockaddr_in * )dest)->sin_port;

    ui->ui_ulen = ui->ui_len;
    if (zerosum == 0) {
#if 1 
        if ((ui->ui_sum == in_chsum()) == 0) {

        }
#else 
        ui->ui_sum = ui->ui_len;
#endif
    }
    ip->ip_v = IPVERSION;
}